#ifndef __TINY_TEST__

#include "vbb_SAVE.h"
#include "vbb_SENSOR.h"
#include "fw/vbb_RTC.h"

void vbb_SAVE_Format(void)
{
    vbb_BACKUP_Clear();
}

bool vbb_SAVE_TestMemory(void)
{
    int i = 0;
    unsigned short val;
    bool ret = TRUE;
    for (i = 0; i < 42; i++)
    {
        if (i >= 11 && i <= 14) // Allocated for RTC
            continue;
        
        val = vbb_BACKUP_Get(i);
        vbb_BACKUP_Set(i, i + 1);
        
        if (vbb_BACKUP_Get(i) != (i + 1))
            ret = FALSE;
        
        vbb_BACKUP_Set(i, val);
        
        if (vbb_BACKUP_Get(i) != val)
            ret = FALSE;
    }
    return ret;
}

void vbb_SAVE_LoadFlashInfo(VBB_FlashMem * FlashMem)
{
    FlashMem->head = 0;
    FlashMem->head |= ((vbb_BACKUP_Get(SAVE_FLASHMEM_HEAD) & 0x0000FFFF) << 16);    
    FlashMem->head |= (vbb_BACKUP_Get(SAVE_FLASHMEM_HEAD + 1) & 0x0000FFFF);
    
    FlashMem->tail = 0;
    FlashMem->tail |= ((vbb_BACKUP_Get(SAVE_FLASHMEM_TAIL) & 0x0000FFFF) << 16);    
    FlashMem->tail |= (vbb_BACKUP_Get(SAVE_FLASHMEM_TAIL + 1) & 0x0000FFFF);
    
    FlashMem->sendhead = 0;
    FlashMem->sendhead |= ((vbb_BACKUP_Get(SAVE_FLASHMEM_SEND) & 0x0000FFFF) << 16);    
    FlashMem->sendhead |= (vbb_BACKUP_Get(SAVE_FLASHMEM_SEND + 1) & 0x0000FFFF);
}

void vbb_SAVE_SaveFlashInfo(VBB_FlashMem * FlashMem)
{    
    vbb_BACKUP_Set(SAVE_FLASHMEM_HEAD, (FlashMem->head & 0xFFFF0000) >> 16);
    vbb_BACKUP_Set(SAVE_FLASHMEM_HEAD + 1, (FlashMem->head & 0x0000FFFF));
    
    vbb_BACKUP_Set(SAVE_FLASHMEM_TAIL, (FlashMem->tail & 0xFFFF0000) >> 16);
    vbb_BACKUP_Set(SAVE_FLASHMEM_TAIL + 1, (FlashMem->tail & 0x0000FFFF));    

    vbb_BACKUP_Set(SAVE_FLASHMEM_SEND, (FlashMem->sendhead & 0xFFFF0000) >> 16);
    vbb_BACKUP_Set(SAVE_FLASHMEM_SEND + 1, (FlashMem->sendhead & 0x0000FFFF));
}

#endif
